package com.googlecode.wcbunittests.test.matchers;

import org.hamcrest.Description;

/**
 * runs a test on a String identifier to see if it's a valid WCB ID. A valid WCB ID
 * contains only lowercase letters.
 * 
 * @since v. 1.0.0 1 feb. 2011
 * @author Freek Wielstra
 *
 */
public class IsValidWcbId extends ContainsOnly  {
    
    /** valid characters, lowercase a-z only. */
    private static final String VALID_CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
    
    public IsValidWcbId() {
        super(VALID_CHARACTERS);
    }
    
    public void describeTo(Description description) {
       description.appendText("A String value containing only ").appendValue(VALID_CHARACTERS);
    }

    @Override
    public boolean matchesSafely(String str) {
        return super.matchesSafely(str);
    }
    
    /*
     * null-safe startsWith / endsWith methods.
     */
    
    private boolean startsWith(String str, String startsWith) {
        return (str == null) ? false : str.startsWith(startsWith);
    }
    
    private boolean endsWith(String str, String endsWith) {
        return (str == null) ? false : str.endsWith(endsWith);
    }

}
